import os
import xlrd
import xlsxwriter

path='C:/Users/24200/Desktop/fsdownload/data'

caoyaodata=xlrd.open_workbook('caoyaodata.xlsx')
image_data=xlrd.open_workbook('test.xlsx')


new_image_data=xlsxwriter.Workbook('new_image_data.xlsx')
new_image_worksheet = new_image_data.add_worksheet(u'sheet1')#在文件中创建一个名为sheet1的sheet"

datasheet=caoyaodata.sheet_by_index(0)
imagesheet=image_data.sheet_by_index(0)
all_data_row=datasheet.nrows
all_image_row=imagesheet.nrows
count = 0
for k in range(1,all_data_row):
    for j in range(0,all_image_row):
        data_row=datasheet.row(k)
        image_row=imagesheet.row(j)
        if data_row[1].value==image_row[1].value:   
            count = count + 1
            new_image_worksheet.write(count,0,data_row[0].value)
            new_image_worksheet.write(count,1,image_row[1].value)
            new_image_worksheet.write(count,2,image_row[2].value)
            new_image_worksheet.write(count,3,image_row[3].value)
              
new_image_data.close() # 保存文件
